<?php

/**
 * model_exam
 */

class Model_exam extends YOU {

	public function __construct()
	{
		parent::__construct();
	}

	/** 读取成配置 **/
	public function getIni()
	{
		$exam_lists = $this->getAll();
		foreach ($exam_lists as $key => $value){
			$exam[$value['exam_id']] = $value['exam_name'];
		}

		return $exam;
	}

	/** 读取列表 **/
	public function getAll($grade_id = 0, $field = "*")
	{
		$where = " WHERE 1=1 ";
		if (!empty($grade_id)){
			$where .= "  AND a.grade_id='{$grade_id}' ";
		}


		$exam_lists = $this->db->fetchAll("SELECT a.*,b.grade_name FROM `tbl_exam` AS a,`tbl_grade` AS b {$where} AND a.grade_id=b.grade_id ");

		return $exam_lists;
	}

	/** 得到数据 **/
	public function getInfo($exam_id, $field = "*")
	{
		$exam_data = $this->db->fetchRow("SELECT {$field} FROM `tbl_exam` WHERE exam_id='{$exam_id}'");

		return $exam_data;
	}

	/** 读取名称根据id **/
	public function getNameById($exam_id)
	{
		$data = $this->getInfo($exam_id, "exam_name");

		return $data['exam_name'];
	}



	/** 年级 列出考试 **/
	public function getListByGrade($grade_id)
	{
		$exam_lists = $this->db->fetchAll("SELECT * FROM `tbl_exam` WHERE grade_id='{$grade_id}'");

		return $exam_lists;
	}

}



?>